package ooday03;

public class PolymorphicDemo {
	public static void main(String[] args) {
		/*
		Animal o = new Dog("小黑",2,"黑");
		Dog g = (Dog) o;
		Swim s = (Swim) o;
		
		System.out.println(o instanceof Dog);
		System.out.println(o instanceof Swim);
		System.out.println(o instanceof Fish);
		if (o instanceof Fish){
			Fish f = (Fish) o;
		}else {
			System.out.println("o不是Fish类型");
		}
		 */
		Animal[] animals = new Animal[5];
		animals[0] = new Dog("小黑",2,"黑");
		animals[1] = new Dog("小白",1,"白");
		animals[2] = new Dog("小金",1,"金");
		animals[3] = new Dog("小花",2,"花");
		animals[4] = new Dog("小灰",3,"灰");
		for (int i=0;i<animals.length;i++){
			System.out.println(animals[i].name);
			animals[i].drink();
			animals[i].eat();
			if (animals[i] instanceof Dog){
				Dog dog = (Dog) animals[i];
				dog.lookHome();
			}
			if(animals[i] instanceof Chick){
				Chick chick = (Chick) animals[i];
				chick.layEggs();
			}
			if (animals[i] instanceof Swim){
				Swim swim = (Swim) animals[i];
				swim.swim();
			}
		}
		/*
		Master master = new Master();
		Animal dog = new Dog("小黑",2,"黑");
		Chick chick = new Chick("小花",3,"花");
		Fish fish = new Fish("小金",1,"金");
		master.feed(dog);
		master.feed(chick);
		master.feed(fish);
		
		 */
		/*
		Dog o1 = new Dog("小黑",2,"黑");
		
		Animal o2 = new Dog("小黑",2,"黑");
		
		Swim o3 = new Dog("小黑",2,"黑");
		
		 */
	}
}
